package com.leo.ibatis.demo.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.leo.ibatis.demo.criteria.OrderstatusCriteria;
import com.leo.ibatis.demo.domain.Orderstatus;
import com.leo.ibatis.demo.service.OrderstatusService;

public class OrderstatusController extends MultiActionController {

	private OrderstatusService orderstatusService;

	public void setOrderstatusService(OrderstatusService orderstatusService) {
		this.orderstatusService = orderstatusService;
	}

	public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception {
		OrderstatusCriteria orderstatusCriteria = new OrderstatusCriteria();
		bind(request, orderstatusCriteria);
		
		List<Orderstatus> orderstatusList = orderstatusService.listOnPage(orderstatusCriteria);
		
		ModelAndView mav = new ModelAndView("orderstatus/list");
		mav.addObject("orderstatusList", orderstatusList);
		mav.addObject("orderstatusCriteria", orderstatusCriteria);
		
		return mav;
	}

	public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) throws Exception {
		OrderstatusCriteria orderstatusCriteria = new OrderstatusCriteria();
		bind(request, orderstatusCriteria);
			
		int linenum = ServletRequestUtils.getRequiredIntParameter(request, "linenum");
		int orderid = ServletRequestUtils.getRequiredIntParameter(request, "orderid");

		Orderstatus orderstatus = orderstatusService.select(linenum, orderid);
		
		ModelAndView mav = new ModelAndView("orderstatus/detail");
		mav.addObject("orderstatus", orderstatus);
		mav.addObject("orderstatusCriteria", orderstatusCriteria);
		
		return mav;
	}

	public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception {
		int linenum = ServletRequestUtils.getRequiredIntParameter(request, "linenum");
		int orderid = ServletRequestUtils.getRequiredIntParameter(request, "orderid");

		orderstatusService.delete(linenum, orderid);
		
		return new ModelAndView("redirect:orderstatus.do");
	}

}
